package com.smsc.headend.task.engine.service;

import com.smsc.headend.cache.service.AbstractAssetManagementService;
import com.smsc.headend.common.utils.R;
import com.smsc.headend.module.asset.dto.MeterPhaseDTO;
import com.smsc.headend.module.asset.entity.Dcu;
import com.smsc.headend.module.asset.entity.Meter;
import com.smsc.headend.module.asset.entity.PlcMeterStatus;
import com.smsc.headend.module.asset.entity.UnRegisterDevice;
import com.smsc.headend.module.common.entity.ScalerUnit;
import com.smsc.headend.module.data.dto.DataItemDTO;
import com.smsc.headend.module.data.entity.MeterRole;
import com.smsc.headend.module.data.query.ModelDataItemQueryItem;
import com.smsc.headend.module.event.dto.DeviceNotificationDto;
import com.smsc.headend.module.fwu.entity.LogFwUpgradeHis;
import com.smsc.headend.module.mdm.entity.LogMdmSync;
import com.smsc.headend.module.report.entity.LogModeSwitchHisSub;
import com.smsc.headend.module.report.entity.LogModeSwitchToPostHisSub;
import com.smsc.headend.module.report.entity.LogPlcNetworkTopology;
import com.smsc.headend.module.template.loadprofile.entity.TemplateLoadProfileEntity;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient(value = "asset-management")
//@FeignClient(value = "asset-management")
public interface FeignAssetManagementService extends AbstractAssetManagementService {

    @RequestMapping("/modelOperation/queryModelDataItemCosem")
    List<DataItemDTO> queryModelDataItemCosem(@RequestBody ModelDataItemQueryItem modelDataItemQueryItem);

    @RequestMapping("/meter/update")
    R updateMeter(@RequestBody Meter meter);

    @RequestMapping("/meter/deleteMeterRelation")
    R deleteMeterRelation(@RequestParam("meterId") Long meterId);

    @RequestMapping("/dcu/update")
    R updateDcu(@RequestBody Dcu dcu);

    /**
     * get Operation's DataItem   according to meter Model's OperationGroup  and seq in OperationGroup
     *
     * @param deviceModel
     * @param groupId
     * @param operationId
     * @param seq
     * @param dataItemId
     * @return
     */
    @RequestMapping("/modelOperation/queryModelOperationDataItemCosem")
    List<DataItemDTO> queryModelOperationDataItemCosem(@RequestParam("deviceModel") Long deviceModel, @RequestParam("groupId") Long groupId
            , @RequestParam("operationId") Long operationId, @RequestParam("seq") Integer seq, @RequestParam("dataItemId") Long dataItemId);

    @RequestMapping("/modelOperation/queryOperationSeqId")
    Integer queryOperationSeqId(@RequestParam("operationGroupId") Long operationGroupId, @RequestParam("operationId") Long operationId);

    @RequestMapping("/measurement/profile/period")
    Integer getProfileIntervalTime(@RequestParam("meterId") Long meterId, @RequestParam("lpTemplateId") Long lpTemplateId);

    @RequestMapping("/measurement/profile/period/LpId")
    Integer getProfileIntervalTimeByLpDataItemId(@RequestParam("meterId") Long meterId, @RequestParam("lpDataItemId") Long lpDataItemId);

    @RequestMapping("/measurement/profile/getTemplateLoadProfileEntity")
    TemplateLoadProfileEntity getTemplateLoadProfileEntity(@RequestParam("meterId") Long meterId, @RequestParam("lpDataItemId") Long lpDataItemId);

    @RequestMapping("/measurement/profile/captureObjects")
    List<DataItemDTO> getProfileDataItemForDevice(@RequestParam("meterId") Long meterId, @RequestParam("lpTemplateId") Long lpTemplateId);

    @RequestMapping("/measurement/profile/intervalType")
    String getProfileIntervalType(@RequestParam("lpTemplateId") Long lpTemplateId);

    @RequestMapping("/meter/getByMfgSn")
    Meter getMeterByMfgSn(@RequestParam("mfgSn") String mfgSn);

    @RequestMapping("/com/updateComStatus")
    int updateComEntityStatus(@RequestParam("comId") Long comId, @RequestParam("type") Integer type);

    @RequestMapping("/com/getOnlineIds")
    List<Long> getOnlineComEntityIds();

    @RequestMapping("/event/pushObjList")
    DeviceNotificationDto getDeviceNotificationItem(@RequestParam("modelId") Long modelId, @RequestParam(required = false) Long dataItemId);

    @RequestMapping("/event/eventType")
    Integer getModelEventType(@RequestParam("modelId") Long modelId, @RequestParam("eventCode") Integer eventCode, @RequestParam(value = "lbDataItemId", required = false) Long lbDataItemId, @RequestParam("deviceTypeId") Long deviceTypeId);

    @RequestMapping("/event/eventName")
    String getEventName(@RequestParam("eventTypeId") Long eventTypeId);

    @RequestMapping("/fwu/fileFwTypeVersion")
    String getFileFirmwareTypeVersion(@RequestParam("fwFileId") Long fwFileId, @RequestParam("fwTypeId") Long fwTypeId);

    @RequestMapping("/fwu/report/get")
    LogFwUpgradeHis getFwuReport(@RequestParam("deviceId") Long deviceId, @RequestParam("deviceType") Long deviceType
            , @RequestParam("configScheduleTaskId") Long configScheduleTaskId, @RequestParam("taskType") Integer taskType);

    @RequestMapping("/fwu/report/getList")
    List<LogFwUpgradeHis> getFwuReportList(@RequestParam("deviceId") Long deviceId, @RequestParam("deviceType") Long deviceType
            , @RequestParam("configScheduleTaskId") Long configScheduleTaskId);

    @RequestMapping("/fwu/report/save")
    int saveFwuReport(@RequestParam("deviceId") Long deviceId, @RequestParam("deviceType") Long deviceType
            , @RequestParam(value = "templateId", required = false) Long templateId
            , @RequestParam("configScheduleTaskId") Long configScheduleTaskId
            , @RequestParam("taskType") Integer taskType
            , @RequestParam(value = "upgradeResult", required = false) Integer upgradeResult
            , @RequestParam(value = "tvStart", required = false) Long tvStart
            , @RequestParam(value = "tvEnd", required = false) Long tvEnd
            , @RequestParam(value = "descr", required = false) String descr);

    @RequestMapping("/devicelog/unregister/meter/report/save")
    int saveUnregisterMeterHis(@RequestParam("meterId") Long meterId, @RequestParam("dcuId") Long dcuId
            , @RequestParam(value = "taskNo") String taskNo
            , @RequestParam(value = "actionType") Integer actionType
            , @RequestParam(value = "src") Integer src
            , @RequestParam(value = "status") Integer status
            , @RequestParam(value = "tvCreate", required = false) Long tvCreate
            , @RequestParam(value = "tvUpdate") Long tvUpdate
            , @RequestParam(value = "descr") String descr);

    @RequestMapping("/deviceParamResult/report/save")
    void saveDeviceParamResultReport(@RequestParam("deviceId") Long deviceId, @RequestParam("deviceType") Long deviceType
            , @RequestParam(value = "src") Integer src
            , @RequestParam(value = "templateId", required = false) Long templateId
            , @RequestParam(value = "templateType", required = false) Integer templateType
            , @RequestParam(value = "dataItemId") Long dataItemId
            , @RequestParam(value = "taskNo") String taskNo
            , @RequestParam(value = "paramName") String paramName
            , @RequestParam(value = "paramResult") String paramResult
            , @RequestParam(value = "paramDesc", required = false) String paramDesc);

    @RequestMapping("/measurement/profile/getLpIdByObis")
    Long getLpDataItemByObis(@RequestParam("meterId") Long meterId, @RequestParam("obis") String obis);

    @RequestMapping("/measurement/profile/getDateItemIdByObisAndModelId")
    Long getDateItemIdByObisAndModelId(@RequestParam("modelId") Long modelId, @RequestParam("obis") String obis);

    @RequestMapping("/measurement/profile/captureObjects/byLpDataItemId")
    List<DataItemDTO> getProfileDataItemForDeviceByLpDataItem(@RequestParam("meterId") Long meterId, @RequestParam("lpDataItem") Long lpDataItem);

    @RequestMapping("/measurement/profile/lpTemplateId")
    Long getLpTemplateIdByDataItemId(@RequestParam Long meterId, @RequestParam Long lpDataItemId);

//    @RequestMapping("/measurement/profile/captureObjects/byLpTemplateId")
//    List<DataItemDTO> getProfileDataItemForDeviceByLpTemplateId(@RequestParam("meterId") Long meterId, @RequestParam("lpTemplateId") Long lpTemplateId);


    @RequestMapping("/measurement/profile/captureObjects/byLpTemplateAndModel")
    List<DataItemDTO> getProfileDataItemForDeviceByLpTemplateIdAndModel(@RequestParam Long modelId, @RequestParam Long lpTemplateId);

    @RequestMapping("/subDataItem/getSubDataItemIdByObisInfo")
    Long getSubDataItemIdByObisInfo(@RequestParam("meterId") Long meterId, @RequestParam("obis") String obis, @RequestParam("classId") Integer classId, @RequestParam("attributeId") Integer attributeId, @RequestParam("optType") String optType, @RequestParam("deviceType") Long deviceType);

    @RequestMapping("/subDataItem/getAnsiSubDataItemId")
    Long getAnsiSubDataItemId(@RequestParam Long meterId, @RequestParam Integer lpSourceSelect, @RequestParam Integer endBlkRdgSourceSelect);

    @RequestMapping("/subDataItem/getSubDataItemDTOByModelAndId")
    DataItemDTO getSubDataItemDto(@RequestParam("meterId") Long meterId, @RequestParam("subDataItemId") Long subDataItemId);

    @RequestMapping("/meter/getMeterListByMfgSnList")
    List<MeterPhaseDTO> getMeterListByMfgSnList(@RequestBody List<String> mfgSNList);

    @RequestMapping("/meter/updateMeterPhase")
    R updateMeterPhase(@RequestBody List<MeterPhaseDTO> meterPhaseDTOList);

    @RequestMapping("/event/profile/captureObjects")
    List<DataItemDTO> getEventProfileDataItemForDevice(@RequestParam("deviceId") Long deviceId, @RequestParam("lbTemplateId") Long lbTemplateId, @RequestParam("deviceType") Long deviceType);

    @RequestMapping("/event/profile/captureObjects/byLbDataItem")
    List<DataItemDTO> getEventProfileDataItemByLbDataItemId(@RequestParam("deviceId") Long deviceId, @RequestParam("lbDataItemId") Long lbDataItemId, @RequestParam("deviceType") Long deviceType);

    @GetMapping("configGlobal/getPropertyValue")
    String getPropertyValue(@RequestParam("propertyId") String propertyId);

    @PostMapping("/scaler/convert")
    String convertDataItemValue(@RequestParam("modelId") Long modelId, @RequestParam("subDateItemId") Long subDateItemId, @RequestParam("value") String value, @RequestParam("appName") String appName);

    @PostMapping("/log/mdmSync/getLast")
    LogMdmSync getLastMdmSyncLog(@RequestParam("deviceId") Long deviceId, @RequestParam("deviceType") Long deviceType, @RequestParam("syncType") String syncType, @RequestParam("syncData") String syncData);

    @RequestMapping("/meter/getMetersByDcuId")
    List<Meter> getMetersByDcuId(@RequestParam("dcuId") Long dcuId);

    @RequestMapping("/device/handlePlcMetersStatus")
    void handlePlcMetersStatus(@RequestParam("comId") Long comId, @RequestParam("serialNums") List<String> serialNums, @RequestParam(value = "status", required = false) Integer status);

    @PostMapping("/scaler/convertWithUnit")
    @ResponseBody
    String convertDataItemValueWithUnit(@RequestParam("modelId") Long modelId, @RequestParam("subDateItemId") Long subDateItemId, @RequestParam("value") String value, @RequestParam("appName") String appName);

    @PostMapping("/scaler/convertValueWithUnit")
    Object[] convertDataItemValWithUnit(@RequestParam("modelId") Long modelId,
                                        @RequestParam("subDateItemId") Long subDateItemId,
                                        @RequestParam("value") String value,
                                        @RequestParam("appName") String appName);

    @PostMapping("/scalerUnit/getByModelIdSubDataItemId")
    @ResponseBody
    ScalerUnit getScalerUnitByModelIdSubDataItemId(@RequestParam("modelId") Long modelId, @RequestParam("subDateItemId") Long subDateItemId);

    @GetMapping("language/i18nInApi")
    String i18nInApi(@RequestParam("key") String key);

    @RequestMapping("unRegisterDevice/record/saveOrUpdate")
    int saveUnRegisterRecord(@RequestParam String deviceSn, @RequestParam Long dcuId, @RequestParam(value = "tvCreate", required = false) Long tvCreate, @RequestParam String descrb);

    @RequestMapping("unRegisterDevice/record/deleteByDeviceSn")
    int deleteUnRegisterRecordByDeviceSn(@RequestParam String deviceSn);

    @RequestMapping("unRegisterDevice/record/getRecordByDeviceSn")
    UnRegisterDevice getUnRegisterRecordByDeviceSn(@RequestParam String deviceSn);

    @RequestMapping("/devicelog/plcNetworkTopoInfo/report/save")
    int savePlcNetworkRecord(@RequestBody List<LogPlcNetworkTopology> list);

    @PostMapping("/scalerUnit/getCoverRate")
    public String getCoverRate(@RequestParam("moduleName") String moduleName,
                               @RequestParam("subDateItemId") Long subDataItemId,
                               @RequestParam("modelId") Long modelId);


    @PostMapping("/scalerUnit/getAppConfigUnitName")
    String getAppConfigUnitName(@RequestParam("moduleName") String moduleName, @RequestParam("subDateItemId") Long subDataItemId);


    @RequestMapping("modeswitch/updateStepStatus")
    void updateStepStatus(@RequestParam("taskId") Long taskId,
                          @RequestParam("meterId") Long meterId,
                          @RequestParam("step") LogModeSwitchHisSub.Step step,
                          @RequestParam("status") Integer status,
                          @RequestParam(value = "tvStart", required = false) Long tvStart,
                          @RequestParam(value = "tvEnd", required = false) Long tvEnd,
                          @RequestParam(value = "descr", required = false) String descr);

    @RequestMapping("logDeviceRelay/updateRecord")
    void updateLogRelayControl(@RequestParam("taskNo") String taskNo, @RequestParam("meterId") Long meterId, @RequestParam(value = "actionType", required = false) Integer actionType, @RequestParam("status") Integer status,
                               @RequestParam(value = "result", required = false) Integer result, @RequestParam(value = "descrb", required = false) String descrb);

    @GetMapping("/modelOperation/queryDataItemCosemByDataItemGroup")
    public DataItemDTO queryDataItemCosemByDataItemGroup(@RequestParam Long deviceModel, @RequestParam Long roleId, @RequestParam Integer deviceActionType,
                                                         @RequestParam Long dataItemGroupId, @RequestParam String subDataItemDesc);

    @GetMapping("/role/role-name")
    public MeterRole getRoleByRoleName(@RequestParam Long deviceModel, @RequestParam String roleName);

    @RequestMapping("/device/roleName")
    String getDeviceRoleName(@RequestParam Long roleId);

    @GetMapping("kms/send")
    R sendToKms(@RequestParam("action") String action, @RequestParam("bizContent") String bizContent);

    @GetMapping("language/i18n")
    String i18n(@RequestParam("key") String key, @RequestParam("locale") String locale);

    @RequestMapping("/device/getPlcMeterStatus")
    PlcMeterStatus getPlcMeterStatus(@RequestParam Long meterId);

    @RequestMapping("/device/updatePlcMeterStatus")
    void updatePlcMeterStatus(@RequestParam Long meterId, @RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "tvUpdate", required = false) Long tvUpdate);

    @RequestMapping("modeswitch/updateStepStatusToPost")
    void updateStepStatusToPost(@RequestParam("taskId") Long taskId,
                                @RequestParam("taskNo") String taskNo,
                                @RequestParam("meterId") Long meterId,
                                @RequestParam("step") Long step,
                                @RequestParam("status") Integer status,
                                @RequestParam(value = "tvStart", required = false) Long tvStart,
                                @RequestParam(value = "tvEnd", required = false) Long tvEnd,
                                @RequestParam(value = "descr", required = false) String descr,
                                @RequestParam(value = "taskEnd", required = false) Boolean taskEnd);

    @GetMapping("/role/getRoleByModelAndSubDataItem")
    Integer getRoleByModelAndSubDataItem(@RequestParam("deviceModelId") Long deviceModelId, @RequestParam("subDataItemId") Long subDataItemId, @RequestParam("actionType") Integer actionType);

    @RequestMapping("/display/profile/captureObjects")
    List<DataItemDTO> getDisplayProfileDataItemForDevice(@RequestParam("meterId") Long meterId, @RequestParam("displayTemplateId") Long displayTemplateId);

    //查询某一步的最新记录
    @RequestMapping("modeswitch/getStepRecordToPost")
    LogModeSwitchToPostHisSub getStepRecordToPost(@RequestParam("taskId") Long taskId,
                                                  @RequestParam("meterId") Long meterId,
                                                  @RequestParam("step") Long step);

    @RequestMapping("/fwScheduleTaskLog/updateLog")
    void updateFwScheduleTaskLog(@RequestParam("taskId") Long taskId, @RequestParam("endTime") Long endTime);
}
